#pragma once

#include "str.h"
#include "array.h"

typedef enum
{
    TYPE_NULL = 0,
    TYPE_BOOL = 1,
    TYPE_NUMBER = 2,
    TYPE_STRING = 3,
    TYPE_ARRAY = 4,
    TYPE_OBJECT = 8,
} value_type_t;

typedef struct value_t value_t;

typedef struct value_t
{
    union
    {
        int num;
        string_t *str;
        struct
        {
            array_t *arr;
            array_t *obj;
        };
    };
    string_t *tag;
    value_type_t type;
} value_t;

typedef struct
{
    string_t *key;
    value_t *v;
} member_t;

int xjil_parse(value_t *v, const char *json, size_t len);
value_t *xjil_value_new(value_type_t type);
void xjil_value_del(value_t *value);